package com.luck.easyfoodbatch.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.bigkoo.convenientbanner.holder.Holder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.luck.easyfoodbatch.R;
import com.luck.easyfoodbatch.mvp.model.GoodModel;
import com.luck.easyfoodbatch.util.HttpUtil;

/**
 * Created by Sai on 15/8/4.
 * 网络图片加载例子
 */
public class GoodsImageHolderView implements Holder<GoodModel.DataBean.ThumbsBean> {
    private ImageView imageView;

    @Override
    public View createView(Context context) {
//        //你可以通过layout文件来创建，也可以像我一样用代码创建，不一定是Image，任何控件都可以进行翻页
//        imageView = new ImageView(context);
//        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        View view = LayoutInflater.from(context).inflate(R.layout.image_layout, null);
        imageView = (ImageView) view.findViewById(R.id.iv_banner);
        return view;
    }

    @Override
    public void UpdateUI(Context context, int position, GoodModel.DataBean.ThumbsBean data) {
        String path = "";
        String thumb = data.getPath();
        if (thumb.startsWith("http")) {
            path = thumb;
        } else {
            path = HttpUtil.IMG_BASE_URL + thumb;
        }
        Glide.with(context)
                .load(path)
                .placeholder(R.mipmap.loading_16b9)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imageView);
    }
}
